﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;

namespace ImageAcquisitionTAL
{
    public static class WIAUtils
    {
        public static void ResetWIA()
        {
            ServiceController Scon = null;
            try
            {
                ServiceController[] ctrls = ServiceController.GetServices();
                foreach (ServiceController ctrl in ctrls)
                {
                    if (ctrl.ServiceName.ToLower() == "stisvc")
                    {
                        if (ctrl.CanStop && ctrl.Status != ServiceControllerStatus.Stopped)
                        {
                            ctrl.Stop();
                            ctrl.WaitForStatus(ServiceControllerStatus.Stopped);
                            ctrl.Start();
                            ctrl.WaitForStatus(ServiceControllerStatus.Running);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Cannot reset WIA", ex);
            }
        }
    }
}

